package com.zc.app.rmi;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created by DELL on 2017/6/12.
 */
public class MyRemoteImpl extends UnicastRemoteObject implements  MyRemote {
    protected MyRemoteImpl() throws RemoteException {

    }

    @Override
    public String sayHello() throws RemoteException {
        return "Server says, 'Hey'";
    }

    public static void main(String[] args){
        try {
            LocateRegistry.createRegistry(12312);
            MyRemote service = new MyRemoteImpl();
            Naming.bind("rmi://192.168.1.105:12312/MyRemote", service);
            System.out.println("MyRemoteServcie 启动成功");
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (AlreadyBoundException e) {
            e.printStackTrace();
        }
    }
}
